home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / book / src / snd.c < prev    next >
Text File  |  1993-07-08  |  2KB  |  82 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <mos.h>
  4. #include <string.h>
  5. #include <egb.h>
  6. #include <sugi.h>
  7. #include "book.h"
  8. #include "lib.h"
  9. #include "keyio.h"
  10. #include "snd.h"
  11. #include "mouse.h"
  12.  
  13.  
  14. int     snd_play( char *file )
  15. {
  16.     static  long    bufsiz = 0 ;
  17.     static  char    *buf = NULL ;
  18.     static  char    *lastfile = NULL ;
  19.     FILE    *fp ;
  20.     int     sw, status = FALSE ;
  21.     long    fsize ;
  22.  
  23.     SND_pcm_sound_delete( -1 ) ;
  24.     SND_pcm_mode_set( 1 ) ;
  25.  
  26.     if( lastfile != NULL && strcmp( lastfile, file ) == 0 && buf != NULL )
  27.         status = TRUE ;
  28.     else
  29.     {
  30.         if( lastfile != NULL )
  31.             free( lastfile ), lastfile = NULL ;
  32.  
  33.         if( ( fp = fopen( file, "rb" ) ) == NULL )
  34.             return ERR ;
  35.  
  36.         if( ( fsize = get_fsize( fp ) ) > bufsiz )
  37.         {
  38.             bufsiz = fsize ;
  39.             if( buf != NULL )
  40.                 free( buf ), buf = NULL ;
  41.         }
  42.  
  43.         if( buf == NULL )
  44.             buf = malloc( bufsiz ) ;
  45.  
  46.         if( buf != NULL )
  47.             if( fread( buf, 1, fsize, fp ) == fsize )
  48.                 if( *(int *)(buf+12) <= fsize-32 )
  49.                 {
  50.                     lastfile = strdup( file ) ;
  51.                     status = TRUE ;
  52.                 }
  53.  
  54.         fclose( fp ) ;
  55.  
  56.         if( status == FALSE )
  57.             return ERR ;
  58.     }
  59.  
  60.     SND_pan_set( 71, 64 ) ;
  61.     *(int *)(buf+20) = 0 ;
  62.     SND_pcm_play2( 71, buf[28], 127, buf ) ;
  63.  
  64.     for( status = ERR+1 ; SND_pcm_status( 71 ) ; )
  65.     {
  66.         mos_rdpos(&sw, NULL,NULL);
  67.         if (sw != 0 || kbhit())
  68.         {
  69.             while (sw != 0)
  70.                 mos_rdpos(&sw, NULL,NULL);
  71.             keyflush();
  72.             status = ERR;
  73.             break;
  74.         }
  75.     }
  76.  
  77.     SND_pcm_play_stop( 71 ) ;
  78.     SND_pcm_rec_stop() ;
  79.  
  80.     return status ;
  81. }
  82.